<?php
/**
 * Constraint that asserts that the array it is evaluated for has a given key.
 *
 * Uses array_key_exists() to check if the key is found in the input array, if not
 * found the evaluaton fails.
 *
 * The array key is passed in the constructor.
 *
 * @category   Testing
 * @package    PHPUnit
 * @author     Jan Borsodi <jb@ez.no>
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
 * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @version    Release: 3.0.0
 * @link       http://www.phpunit.de/
 * @since      Class available since Release 3.0.0
 */
class Constraint_ArrayNotHasNull extends Constraint{
    private $value;
    private $key;

    public function __construct(){
    }

    /**
     * Evaluates the constraint for parameter $other. Returns TRUE if the
     * constraint is met, FALSE otherwise.
     *
     * @param mixed $other Value or object to evaluate.
     * @return bool
     */
    public function evaluate($array){
    	$testResult = array();
    	foreach ($array as $key=>$value){
    		$isNull = !empty($value);
    		if(!$isNull){
    			$this->key[] = $key;
    		}
    		$testResult[] = $isNull;
    	}
        return count($array) == count(array_filter($testResult));
    }

    /**
     * Returns a string representation of the constraint.
     *
     * @return string
     * @access public
     */
    public function toString(){
        return 'has null in the key: ' .implode(',',$this->key);
    }
}
?>
